package com.secondary.action.goodsAction;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.secondary.action.BaseAction;
import com.secondary.pojos.Category;
import com.secondary.pojos.Goods;
import com.secondary.service.CategoryService;
import com.secondary.service.GoodsService;

@ParentPackage(value = "struts-default")
@Namespace(value = "/goods")
@Action(value = "showGoods")
@Results( {
		@Result(name = "list", location = "/showGoods/showGoods.jsp"),
		@Result(name = "findGood", location = "/showGoods/showGoodInfo.jsp"),
		@Result(name = "listSearch", location = "/showGoods/showSearchGoods.jsp"), })
public class GoodsAction extends BaseAction {
	@Resource
	private GoodsService goodsService;
	@Resource
	private CategoryService categoryService;
	private List<Goods> goodList;
	private List<Category> subCategoryList;
	private int pid;
	private Goods good;
	private Category parentCate;

	public String listByPid() {
		pid = Integer.parseInt(super.getRequestParameter("pid"));
		parentCate = categoryService.findParentCategoryObject(pid);
		subCategoryList = categoryService.findParentCategory(pid);
		goodList = goodsService.listGoodsByParentId(pid);
	
		return "list";
	}

	public String findGoodInfo() {
		int id = Integer.parseInt(super.getRequestParameter("id"));
		good = goodsService.findGood(id);
		return "findGood";

	}

	public String findGoodsByName() {
		String name = super.getRequestParameter("name");
		goodList = goodsService.findGoodsByName(name);
		return "listSearch";
	}

	public GoodsService getGoodsService() {
		return goodsService;
	}

	public void setGoodsService(GoodsService goodsService) {
		this.goodsService = goodsService;
	}

	public List<Goods> getGoodList() {
		return goodList;
	}

	public void setGoodList(List<Goods> goodList) {
		this.goodList = goodList;
	}

	public int getPid() {
		return pid;
	}

	public void setPid(int pid) {
		this.pid = pid;
	}

	public CategoryService getCategoryService() {
		return categoryService;
	}

	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}

	public List<Category> getSubCategoryList() {
		return subCategoryList;
	}

	public void setSubCategoryList(List<Category> subCategoryList) {
		this.subCategoryList = subCategoryList;
	}

	public Goods getGood() {
		return good;
	}

	public void setGood(Goods good) {
		this.good = good;
	}

	public Category getParentCate() {
		return parentCate;
	}

	public void setParentCate(Category parentCate) {
		this.parentCate = parentCate;
	}

}
